package com.ourteam.product.api;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ourteam.frame.controller.AbstractCRUDServiceController;
import com.ourteam.product.ui.dao.ProductUIPageTemplateDAOQueryBean;
import com.ourteam.product.ui.domain.ProductUIPageTemplateBean;
import com.ourteam.product.ui.service.IProductUIService;
import com.ourteam.product.ui.service.ProductUIServiceFactory;

@Controller
@RequestMapping("/api/PRODUCT/UI/ProductUIPageTemplate")
public class ProductUIPageTemplateAPI extends
		AbstractCRUDServiceController<ProductUIPageTemplateDAOQueryBean, ProductUIPageTemplateSearchModel, ProductUIPageTemplateBean> {

	private static final IProductUIService PRODUCT_UI_SERVICE = ProductUIServiceFactory.getProductUIService();

	@Override
	protected ProductUIPageTemplateDAOQueryBean newQueryBean() {
		return new ProductUIPageTemplateDAOQueryBean();
	}

	@Override
	protected int queryCount(ProductUIPageTemplateDAOQueryBean queryBean) throws Exception {
		return PRODUCT_UI_SERVICE.queryProductUIPageTemplateCount(queryBean);
	}

	@Override
	protected ProductUIPageTemplateBean[] queryData(ProductUIPageTemplateDAOQueryBean queryBean) throws Exception {
		return PRODUCT_UI_SERVICE.queryProductUIPageTemplates(queryBean);
	}

	@Override
	protected void deleteData(long[] ids) throws Exception {
		PRODUCT_UI_SERVICE.deleteProductUIPageTemplates(ids);
	}

	@Override
	protected ProductUIPageTemplateBean getDataById(long id) throws Exception {
		return PRODUCT_UI_SERVICE.getProductUIPageTemplateById(id);
	}

	@Override
	protected void saveData(ProductUIPageTemplateBean dataBean) throws Exception {
		dataBean.setLastModifyUser(getLoginUserName());
		if (dataBean.getId() == 0) {
			PRODUCT_UI_SERVICE.addNewProductUIPageTemplate(dataBean);
		} else {
			PRODUCT_UI_SERVICE.modifyProductUIPageTemplate(dataBean);
		}
	}
	
	@RequestMapping("/getPageTemplateList")
	@ResponseBody
	public ProductUIPageTemplateBean[] getPageTemplateList() throws Exception{
		return PRODUCT_UI_SERVICE.queryProductUIPageTemplates(null);
	}
	

}
